Adding a group sort field

This scenario requires a report that already contains a group which also must contain a summary field.

A Group Sort Field can only exist if the group contains a summary field, because that summary field is what the Sort is based on. In this example, the report is grouped on {Customer.Region} and the summary field is the "SUM of Customer.Last Year's Sales (Currency)".

To add a group sort field you can use code similar to the following:

  1. Place this code in the General Declarations section.
Dim CRXReport As New CrystalReport1 'The existing report (ActiveX Designer) 
Dim CRXSortFields As CRAXDRT.SortFields 
Dim CRXSummaryField As CRAXDRT.SummaryFieldDefinition 
  1. Place this code in the FORM_LOAD event procedure.
Private Sub Form_Load() 
  1. This code gets the SortFields collection for the groups:
Set CRXCRXSortFields = CRXReport.GroupSortFields 
  1. Get the first Summary Field which is the '"SUM of Customer.Last Year's Sales (Currency)".
Set CRXSummaryField = CRXReport.SummaryFields.Item(1) 
  1. Now add the Group Sort Field.
CRXSortFields.Add CRXSummaryField, crDescendingOrder 
  1. Finally, display the report.
CRViewer1.ReportSource = CRXReport 
CRViewer1.ViewReport 

End Sub



Seagate Software IMG Holdings, Inc.
http://www.seagatesoftware.com
Support services:
http://support.seagatesoftware.com